<?php

namespace app\teacher\controller\system;
use app\common\controller\Frontend;
use app\common\enums\AcceptAccountTypeEnum;
use app\common\model\banxi\sys\SysNotification as SysNotificationModel;
use app\common\model\banxi\sys\SysNotificationAccept;

class SysNotification  extends Frontend
{

    /*
     * 分页-通知公告
     * */
    public function listMyNotification()
    {
        $limit = $this->request->get('limit', 20);
        $index = $this->request->get('index', 1);
        $searchText = $this->request->get('searchText', '');

        $accountId = $this->auth->id;
        $accountType = $this->auth::TOKEN_TYPE;
        $SysNotificationModel = new SysNotificationModel();
        $list = $SysNotificationModel->listMyInfoPage($index, $limit, $accountId, $accountType, $searchText);

        $this->ok('操作成功', result_row($list));
    }

    /*
     * 查询-通知详情
     * */
    public function getNotificationInfo()
    {
        $id = $this->request->get('id', 0);

        $accountId = $this->auth->id;
        $accountType = AcceptAccountTypeEnum::TRAINER;

        $SysNotificationAcceptModel = new SysNotificationAccept();
        $SysNotificationAcceptModel->markRead($id, $accountId, $accountType);

        $SysNotificationModel = new SysNotificationModel();
        $info = $SysNotificationModel->getInfo(['id' => $id]);

        $this->ok('操作成功', $info);
    }

    /*
     * 查询-未读数量
     * */
    public function getMyUnreadCount()
    {
        $accountId = $this->auth->id;
        $accountType = AcceptAccountTypeEnum::TRAINER;

        $SysNotificationModel = new SysNotificationModel();
        $info = $SysNotificationModel->getMyUnreadCount($accountId, $accountType);

        $this->ok('操作成功', $info);
    }
}